package com.gitee.leijin.rbac.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

@Slf4j
public class AjaxUtils {

    public static void response(HttpServletResponse response, String data) {
        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        try (PrintWriter pw = response.getWriter()) {
            pw.print(data);
            pw.flush();
        } catch (IOException e) {
            log.error("写入数据异常", e);
        }
    }
}
